package aip.core.model.user;

import java.io.Serializable;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

import org.springframework.util.StringUtils;

@Entity
@Table(name = "USER_EXPERT")
public class Expert implements Serializable
{
    private static final long serialVersionUID = -3342329994169734323L;
    private String username;
    /** 专家领域 */
    private String domainStr;

    /**
     * @return the username
     */
    @Id
    @Column(name = "USERNAME_")
    public String getUsername()
    {
        return username;
    }

    /**
     * @param username
     *        the username to set
     */
    public void setUsername(String username)
    {
        this.username = username;
    }

    /**
     * @return the domainStr
     */
    @Column(name = "DOMAIN_")
    public String[] getDomain()
    {
        return StringUtils.hasText(domainStr) ? domainStr.substring(1,
                domainStr.length() - 1).split("|") : new String[] {};
    }

    public Set<Integer> getDomainSet()
    {
        Set<String> result = new HashSet<String>();
        result.addAll(Arrays.asList(this.getDomain()));
        // 把特殊符号与空值去掉
        result.remove("|");
        result.remove("");
        Set<Integer> domainSet = new HashSet<Integer>();
        for (String doamin : result)
        {
            domainSet.add(Integer.valueOf(doamin));
        }
        return domainSet;
    }

    /**
     * @param domainStr
     *        the domainStr to set
     */
    public void setDomain(String[] domain)
    {
        this.domainStr = '|' + StringUtils.arrayToDelimitedString(domain, "|") + '|';
    }

    /**
     * @return the domainStr
     */
    public String getDomainStr()
    {
        return domainStr;
    }

    /**
     * @param domainStr
     *        the domainStr to set
     */
    public void setDomainStr(String domainStr)
    {
        this.domainStr = domainStr;
    }
}
